
<%@ page import="ratemymacclass.Professor" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'professor.label', default: 'Professor')}" />
        <title>${professorInstance.firstName} ${professorInstance.lastName}<g:message args="[entityName]" /></title>
    </head>
    <body>
        <div class="nav" style="text-align:center;">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="Home"/></a></span>
            <span class="menuButton"><g:link class="list" action="list"><g:message code="List of Professor" args="[entityName]" /></g:link></span>
            <span class="menuButton"><g:link class="create" action="create"><g:message code="Add A New Professor" args="[entityName]" /></g:link></span>

        </div>
        <div class="body">
            <h1>${professorInstance.firstName} ${professorInstance.lastName}<g:message args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="dialog">
                <table>
                    <tbody>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="professor.firstName.label" default="First Name" /></td>
                            
                            <td valign="top" class="value">${fieldValue(bean: professorInstance, field: "firstName")}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="professor.lastName.label" default="Last Name" /></td>
                            
                            <td valign="top" class="value">${fieldValue(bean: professorInstance, field: "lastName")}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="professor.department.label" default="Department" /></td>
                            
                            <td valign="top" class="value">${fieldValue(bean: professorInstance, field: "department")}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="professor.email.label" default="Email" /></td>
                            
                            <td valign="top" class="value">${fieldValue(bean: professorInstance, field: "email")}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="professor.profRatings.label" default="Prof Ratings" /></td>

                            <td valign="top" style="text-align: left;" class="value">
                                <ul>
                                <g:if test="${!(professorInstance.profRatings)}">
                                    This professor has no ratings yet.
                                    %{--<g:def var="ratedProf" value="${professorInstance?.id}"/>--}%
                                    %{--<g:link controller="profRating" class="create" action="create" params="[profID: ratedProf]">Rate this Professor now!</g:link>--}%
                                </g:if>
                                <g:else>
                                    Professor ${professorInstance?.lastName} has been rated ${professorInstance?.profRatings?.size()} time(s).
                                    Below are their averages:  <br/> <br />
                                    <table style="text-align: center" border="0"><tr>
                                        <td><g:message code="profRating.hot.label" default="Hot" /></td>
                                        <td><g:message code="profRating.clarity.label" default="Clarity" /></td>
                                        <td><g:message code="profRating.accessible.label" default="Accessible" /></td>
                                        <td><g:message code="profRating.textbook.label" default="Textbook" /></td>
                                    </tr>

                                    <tr>
                                        <td>${(float)professorInstance?.profRatings?.hot?.sum()/professorInstance?.profRatings?.hot?.size()}</td>
                                        <td>${(float)professorInstance?.profRatings?.clarity?.sum()/professorInstance?.profRatings?.clarity?.size()}</td>
                                        <td>${(float)professorInstance?.profRatings?.accessible?.sum()/professorInstance?.profRatings?.accessible?.size()}</td>
                                        <td>${(float)professorInstance?.profRatings?.textbook?.sum()/professorInstance?.profRatings?.textbook?.size()}</td>
                                    </tr></table>

                                </g:else>

                                %{--<g:each in="${professorInstance.profRatings}" var="p">--}%
                                    %{--<li><g:link controller="profRating" action="show" id="${p.id}">${p?.encodeAsHTML()}</g:link></li>--}%
                                %{--</g:each>--}%
                                </ul>
                            </td>

                        </tr>
                    
                        %{--<tr class="prop">--}%
                            %{--<td valign="top" class="name"><g:message code="professor.rating.label" default="Rating" /></td>--}%
                            %{----}%
                            %{--<td valign="top" class="value"><g:link controller="rating" action="show" id="${professorInstance?.rating?.course}">${professorInstance?.rating?.encodeAsHTML()}</g:link></td>--}%
                            %{----}%
                        %{--</tr>--}%
                    <br />
                    <tr><td></td>
                        <td style="float: right;">
                        <g:def var="ratedProf" value="${professorInstance?.id}"/>
                        <button><g:link controller="profRating" class="create" action="create" params="[profID: ratedProf]">Rate this professor</g:link></button>
                    </td></tr>
                    </tbody>
                </table>
            </div>
            <div class="buttons">
                <g:form>
                    <g:hiddenField name="id" value="${professorInstance?.id}" />
                    <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
                    <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
                </g:form>
            </div>
        </div>
    </body>
</html>
